import Vue from 'vue'
import App from './App'

import pageHead from './components/page-head.vue'
import pageFoot from './components/page-foot.vue'

import store from './store'

Vue.config.productionTip = false

Vue.prototype.$store = store
Vue.prototype.$backgroundAudioData = {
	playing: false,
	playTime: 0,
	formatedPlayTime: '00:00:00'
}

const axios = {
	baseUrl: 'http://192.168.1.126:3000/',
	getToken() {
		return uni.getStorageSync('authorization');
	},
	get(requestUrl, data, callback,failcallback) {
		uni.showLoading({
			title: '拼命加载中...'
		});
		uni.request({
			url: (this.baseUrl + requestUrl).trim(),
			data: data,
			header: {
				'authorization': this.getToken() || '', //自定义请求头信息
			},
			success: (res) => {
				callback(res)
			},
			fail: (err) => {
				failcallback(err)
			},
			complete: () => {
				uni.hideLoading();
			}
		})

	},
	post(requestUrl, data, callback,failcallback) {
		uni.showLoading({
			title: '拼命加载中...'
		});
		uni.request({
			url: (this.baseUrl + requestUrl).trim(),
			data: data,
			method: 'POST',
			header: {
				'authorization': this.getToken(), //自定义请求头信息
			},
			success: (res) => {
				callback(res)
			},
			fail: (err) => {
				failcallback(err)
			},
			complete: () => {
				uni.hideLoading();
			}
		})
	},

	put(requestUrl, data, callback,failcallback) {
		uni.showLoading({
			title: '拼命加载中...'
		});
		uni.request({
			url: (this.baseUrl + requestUrl).trim(),
			data: data,
			method: 'PUT',
			header: {
				'authorization': this.getToken(), //自定义请求头信息
			},
			success: (res) => {
				callback(res)
			},
			fail: (err) => {
				failcallback(err)
			},
			complete: () => {
				uni.hideLoading();
			}
		})
	},
	
	del(requestUrl, data, callback,failcallback) {
		uni.showLoading({
			title: '拼命加载中...'
		});
		uni.request({
			url: (this.baseUrl + requestUrl).trim(),
			data: data,
			method: 'DELETE',
			header: {
				'authorization': this.getToken(), //自定义请求头信息
			},
			success: (res) => {
				callback(res)
			},
			fail: (err) => {
				failcallback(err)
			},
			complete: () => {
				uni.hideLoading();
			}
		})
	},


}

Vue.prototype.$axios = axios



const global={
	
}
Vue.prototype.$global = global

Vue.component('page-head', pageHead)
Vue.component('page-foot', pageFoot)


App.mpType = 'app'

const app = new Vue({
	store,
	...App
})
app.$mount()
